package hcs.model;

import hcs.interfaces.RoomManagementStrategy;
import hcs.model.Room.WindowState;

/**
 * Implements the away strategy.
 */
public class AwayManagementStrategy extends RoomManagementStrategy {
	
	/**
	 * Instantiate an away strategy for the requested room
	 * @param room the room to be controlled.
	 */
	public AwayManagementStrategy(Room room) {
		super(room);
	}

	@Override
	protected double getTemperatureToFollow() {
		return room.getSettings().getStandardAwayTemp();
	}

	@Override
	protected WindowState roomIsOK() {
		// the room is at the right temperature, try to keep it
		room.setHeaterTarget(getTemperatureToFollow());
		
		// we want the window closed
		return WindowState.CLOSED;
	}

	@Override
	protected WindowState roomIsTooCool() {
		Environment env = room.getHouseController().getEnvironment();
		WindowState desiredWS;
		// the room is cooler than the requested temperature, try to warm it	
		// put the heater at maximum temperature
		room.setHeaterTarget(70);

		// check if it is suitable to open the window
		if (env.getTemperature() > room.getTemperature()) {
			// outside is warmer than inside, and we must warm inside, let's open the window
			desiredWS = WindowState.OPEN;
		} else {
			// outside is cooler than inside, close the window
			desiredWS = WindowState.CLOSED;
		}
		return desiredWS;
	}

	@Override
	protected WindowState roomIsTooWarm() {
		// the room is warmer than requested. Do not try to cool it down, but shut down
		// the heater, not to waste energy
		room.setHeaterTarget(0);
		return WindowState.CLOSED;
	}
}
